package com.oa.android.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.oa.android.R;
import com.oa.android.entry.Txl;
import java.util.List;
import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by  on 2016/6/14.
 */
public class TxlAdapter extends BaseAdapter {

    private Context context;
    private List<Txl> txlList;

    public TxlAdapter(Context context, List<Txl> list) {
        this.context = context;
        this.txlList = list;
    }

    @Override
    public int getCount() {
        return txlList.size();
    }


    @Override
    public Object getItem(int position) {
        return txlList.get(position);
    }


    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {

            convertView = LayoutInflater.from(context).inflate(R.layout.txl_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        final Txl txl = txlList.get(position);
        if (null != txl) {
            viewHolder.comAddress.setText("单位名称："+txl.getDWMC() + "");
            viewHolder.comCell.setText("单位电话："+txl.getDWDH()+"");
            viewHolder.name.setText("姓名："+txl.getXM()+"");
            viewHolder.sex.setText("性别："+txl.getSEX()+"");
            viewHolder.phone.setText("手机号："+txl.getMOBILE()+"");
            viewHolder.emil.setText("邮件："+txl.getEMAIL()+"");
            viewHolder.qq.setText("QQ："+txl.getQQ()+"");
            if(txl.getIFSHARE().equals("0")){
                viewHolder.isShere.setText("已共享");
            }else{
                viewHolder.isShere.setText("未共享");
            }
            viewHolder.cell.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Uri telUri = Uri.parse("tel:" +txl.getMOBILE());
                    Intent intent = new Intent(Intent.ACTION_DIAL, telUri);
                    context.startActivity(intent);
                }
            });

        }
        return convertView;
    }


    class ViewHolder {
        @InjectView(R.id.name)
        TextView name;
        @InjectView(R.id.sex)
        TextView sex;
        @InjectView(R.id.phone)
        TextView phone;
        @InjectView(R.id.comCell)
        TextView comCell;
        @InjectView(R.id.emil)
        TextView emil;
        @InjectView(R.id.comAddress)
        TextView comAddress;
        @InjectView(R.id.Qq)
        TextView qq;
        @InjectView(R.id.isShere)
        TextView isShere;
        @InjectView(R.id.cell)
        ImageView cell;


        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
